﻿using System;
using System.Windows.Forms;

//自定义命名空间
using DreamCube.Foundation.Basic.Extensions.System;

namespace WebServer.UI
{
    public partial class WebBindingEditForm : Form
    {
        #region "字段"

        private Service.Model.WebBinding binding;

        #endregion 

        #region "属性"

        /// <summary>
        /// 获取绑定对象
        /// </summary>
        public Service.Model.WebBinding WebBinding
        {
            get
            {
                if (this.binding == null) this.binding = new Service.Model.WebBinding();
                this.binding.Protocol = comboBox1.SelectedValue.ToString();
                this.binding.Hostname = textBox2.Text;
                this.binding.Port = textBox1.Text.TryToInt32();
                return this.binding;
            }
        }

        #endregion

        #region "公共方法"

        public WebBindingEditForm(Service.Model.WebBinding binding)
        {
            InitializeComponent();
            this.binding = binding;
        }

        public WebBindingEditForm()
            : this(null)
        { }

        #endregion

        #region "私有方法"

        private void BindListEditForm_Load(object sender, EventArgs e)
        {
            if (this.binding != null)
            {
                comboBox1.SelectedValue = this.binding.Protocol;
                textBox1.Text = this.binding.Port.ToString();
                textBox2.Text = this.binding.Hostname;
            }
        }

        /// <summary>
        /// 确定按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        /// <summary>
        /// 取消按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        #endregion
    }
}
